/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package tweet.dl.view;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import tweet.dl.*;
import twitter4j.TwitterException;

/**
 *
 * @author mespinozas
 */
public class MainView extends javax.swing.JFrame {
    private static MainView instance;
    /**
     * Creates new form MainView
     */
    private MainView() {
        
        initComponents();
    }
    
    public static MainView getInstance()
    {
        if(instance==null)
            return new MainView();
        else
            return instance;
    }
    
    private int getSampleSize()
    {
        return 100;
        //TweetDl.getInstance()
    }
   
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        AuthenticateLabel = new javax.swing.JLabel();
        AuthenticateBTN = new javax.swing.JButton();
        sampleLabel = new javax.swing.JLabel();
        sampleSpinner = new javax.swing.JSpinner();
        captureBTN = new javax.swing.JToggleButton();
        fieldsPanel = new javax.swing.JPanel();
        textCB = new javax.swing.JCheckBox();
        idCB = new javax.swing.JCheckBox();
        userCB = new javax.swing.JCheckBox();
        screenNameCB = new javax.swing.JCheckBox();
        userNameCB = new javax.swing.JCheckBox();
        countryCB = new javax.swing.JCheckBox();
        createdAtCB = new javax.swing.JCheckBox();
        countryCB = new javax.swing.JCheckBox();
        contributorCB = new javax.swing.JCheckBox();
        langCB = new javax.swing.JCheckBox();
        placeCB = new javax.swing.JCheckBox();
        sourceCB = new javax.swing.JCheckBox();
        platformCB = new javax.swing.JCheckBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Tweet-dl");

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("properties/Languaje_es"); // NOI18N
        AuthenticateLabel.setText(bundle.getString("AskAuthKey")); // NOI18N

        AuthenticateBTN.setText(bundle.getString("AuthenticateKey")); // NOI18N
        AuthenticateBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AuthenticateBTNActionPerformed(evt);
            }
        });

        sampleLabel.setText(bundle.getString("SampleSizeKey")); // NOI18N

        sampleSpinner.setValue(100);

        captureBTN.setText(bundle.getString("StartKey")); // NOI18N
        captureBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                captureBTNActionPerformed(evt);
            }
        });

        fieldsPanel.setLayout(new java.awt.GridLayout(8, 4));

        java.util.ResourceBundle bundle1 = java.util.ResourceBundle.getBundle("properties/ExportFields"); // NOI18N
        textCB.setText(bundle1.getString("TextNameKey")); // NOI18N
        fieldsPanel.add(textCB);

        idCB.setText(bundle1.getString("IdNameKey")); // NOI18N
        fieldsPanel.add(idCB);

        userCB.setText(bundle1.getString("UserKey")); // NOI18N
        fieldsPanel.add(userCB);

        screenNameCB.setText(bundle1.getString("UserScreenNameKey")); // NOI18N
        fieldsPanel.add(screenNameCB);

        userNameCB.setText(bundle1.getString("UserNameKey")); // NOI18N
        fieldsPanel.add(userNameCB);

        countryCB.setText(bundle1.getString("CountryNameKey")); // NOI18N
        fieldsPanel.add(countryCB);

        createdAtCB.setText(bundle1.getString("CreatedAtNameKey")); // NOI18N
        fieldsPanel.add(createdAtCB);

        countryCB.setText(bundle1.getString("CountryNameKey")); // NOI18N
        fieldsPanel.add(countryCB);

        contributorCB.setText(bundle1.getString("ContributorsNameKey")); // NOI18N
        fieldsPanel.add(contributorCB);

        langCB.setText(bundle1.getString("LangNameKey")); // NOI18N
        fieldsPanel.add(langCB);

        placeCB.setText(bundle1.getString("PlaceNameKey")); // NOI18N
        fieldsPanel.add(placeCB);

        sourceCB.setText(bundle1.getString("SourceNameKey")); // NOI18N
        fieldsPanel.add(sourceCB);

        platformCB.setText(bundle1.getString("PlatformKey")); // NOI18N
        fieldsPanel.add(platformCB);

        jMenu1.setText(bundle.getString("FileKey")); // NOI18N
        jMenuBar1.add(jMenu1);

        jMenu2.setText(bundle.getString("EditKey")); // NOI18N
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(captureBTN, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(90, 90, 90))
            .addGroup(layout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fieldsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 457, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(AuthenticateLabel)
                            .addComponent(sampleLabel))
                        .addGap(37, 37, 37)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(AuthenticateBTN, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                            .addComponent(sampleSpinner))))
                .addContainerGap(138, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AuthenticateLabel)
                    .addComponent(AuthenticateBTN))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sampleLabel)
                    .addComponent(sampleSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(fieldsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 148, Short.MAX_VALUE)
                .addComponent(captureBTN)
                .addGap(52, 52, 52))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AuthenticateBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AuthenticateBTNActionPerformed
        // TODO add your handling code here:
        TweetDl.requestAuthorization();
        
    }//GEN-LAST:event_AuthenticateBTNActionPerformed

    private void captureBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_captureBTNActionPerformed
        // TODO add your handling code here:
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("properties/Languaje_es");
        try{
            if(captureBTN.isSelected())
            {
                int showConfirmDialog;
                showConfirmDialog = JOptionPane.showConfirmDialog(rootPane, bundle.getString("FileDeletionKey"));
                
                if(showConfirmDialog==0)
                {
                    captureBTN.setText(bundle.getString("StopCaptureKey"));
                
                    TweetDl.startCapture();
                }
            }
            else
            {
                //java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("properties/Languaje_es");
                captureBTN.setText(bundle.getString("StartCaptureKey"));
                TweetDl.stopCapture();
            }
        }
        catch(TwitterException e)
        {
        }
    }//GEN-LAST:event_captureBTNActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AuthenticateBTN;
    private javax.swing.JLabel AuthenticateLabel;
    private javax.swing.JToggleButton captureBTN;
    private javax.swing.JCheckBox contributorCB;
    private javax.swing.JCheckBox countryCB;
    private javax.swing.JCheckBox createdAtCB;
    private javax.swing.JPanel fieldsPanel;
    private javax.swing.JCheckBox idCB;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JCheckBox langCB;
    private javax.swing.JCheckBox placeCB;
    private javax.swing.JCheckBox platformCB;
    private javax.swing.JLabel sampleLabel;
    private javax.swing.JSpinner sampleSpinner;
    private javax.swing.JCheckBox screenNameCB;
    private javax.swing.JCheckBox sourceCB;
    private javax.swing.JCheckBox textCB;
    private javax.swing.JCheckBox userCB;
    private javax.swing.JCheckBox userNameCB;
    // End of variables declaration//GEN-END:variables

   
}
